package cn.dwj.hadoop.mr.flowsum;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * Created by Administrator on 2017/12/27 0027.
 */
public class FlowBean implements WritableComparable<FlowBean>
{
    private String phoneNB;
    private long upFlow;
    private long dFlow;
    private long sFlow;

    public FlowBean(){

    }

    public FlowBean(String phoneNB, long upFlow, long dFlow) {
        this.phoneNB = phoneNB;
        this.upFlow = upFlow;
        this.dFlow = dFlow;
        this.sFlow = upFlow + dFlow;
    }

    public String getPhoneNB() {
        return phoneNB;
    }

    public void setPhoneNB(String phoneNB) {
        this.phoneNB = phoneNB;
    }

    public long getUpFlow() {
        return upFlow;
    }

    public void setUpFlow(long upFlow) {
        this.upFlow = upFlow;
    }

    public long getdFlow() {
        return dFlow;
    }

    public void setdFlow(long dFlow) {
        this.dFlow = dFlow;
    }

    public long getsFlow() {
        return sFlow;
    }

    public void setsFlow(long sFlow) {
        this.sFlow = sFlow;
    }

    //将对象数据序列化到流中
    public void write(DataOutput out) throws IOException {
        out.writeUTF(phoneNB);
        out.writeLong(upFlow);
        out.writeLong(dFlow);
        out.writeLong(sFlow);
    }

    //从流中反序列出对象数据
    //从流中读出对象时，必须跟序列化的顺序保持一致
    public void readFields(DataInput in) throws IOException {
        phoneNB = in.readUTF();
        upFlow = in.readLong();
        dFlow = in.readLong();
        sFlow = in.readLong();
    }

    @Override
    public String toString() {
        return
                upFlow + "\t"
                + dFlow + "\t"
                + sFlow;
    }

    public int compareTo(FlowBean o) {
        return sFlow>o.getsFlow()?-1:1;
    }
}
